package com.leo.test.springbootdemo;

import com.google.gson.Gson;
import com.leo.test.springbootdemo.config.CacheService;
import com.leo.test.springbootdemo.config.DataConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class SpringbootDockerApplication {

	@Autowired
	private DataConfig dataConfig;

	@Autowired
	private CacheService cacheService;

	public static void main(String[] args) {
		SpringApplication.run(SpringbootDockerApplication.class, args);
	}

	@GetMapping
	public String indexc(){
		System.out.println("--------SpringbootdemoApplication----------");
		return "success";
	}

	@GetMapping("data")
	public String data(){
		Gson gson = new Gson();
		System.out.println("------------------"+gson.toJson(dataConfig.getMap()));
		return gson.toJson(dataConfig.getList());
	}

	@GetMapping("redissonSet")
	public Object redissonSet(String k,String v){
		cacheService.set(k, v);
		return cacheService.get(k);
	}

	@GetMapping("redissonGetSet")
	public Object redissonGetSet(String k,String v){
		return cacheService.get(k);
	}
	/*@Autowired
	private RedissonClient redissonClient;
	@GetMapping("redissonSet")
	public Object redissonSet(String k,String v){
		RBucket<Object> rBucket = RedissionUtil.getInstance().getRBucket(redissonClient, k);
		rBucket.set(v);
		return rBucket.get();
	}

	@GetMapping("redissonGetSet")
	public Object redissonGetSet(String k,String v){
		RBucket<Object> rBucket = RedissionUtil.getInstance().getRBucket(redissonClient, k);
//		rBucket.set(v);
		return rBucket.getAndSet(v);
	}*/

}
